<!-- 盘点报告列表 -->
<template>
  <view class="container">
    <view class="main">
      <view v-if="pandianReportList.length === 0" class="empty">
        <view class="img">
          <image src="http://jiales.gz-yami.com/addr.png" />
        </view>
        <view class="txt"> 您还没有生成盘点报告记录 </view>
      </view>
      <radio-group class="radio-group">
        <block v-for="(item, index) in pandianReportList" :key="index">
          <view class="address">
            <view class="personal" @tap="selAddrToOrder(item)">
              <view class="info-tit">
                <text class="name">
                  {{ item.title }}
                </text>
                <text class="tel"> 生成盘点报告人：{{ item.name }}， </text>
                <image
                  src="@/static/images/icon/revise.png"
                  :data-reportId="item.uuid"
                  @tap.stop="toPandianReportDetail"
                />
              </view>
              <view class="info-tit">
                <text class="tel"> 原有数量：{{ item.originalNum }}， </text>
                <text class="tel"> 盘点数量：{{ item.pdNum }}， </text>
                <text class="tel"> 丢失数量：{{ item.lostNum }} </text>
              </view>
              <view class="info-tit">
                <text class="tel"> {{ item.reportDetail }}， </text>
              </view>
              <view class="addr">
                <text class="addr-get"> 地址：{{ item.address }} </text>
                状态：
                <uni-tag
                  v-if="item.status === '0'"
                  text="未开始"
                  type="error"
                  size="small"
                />
                <uni-tag
                  v-if="item.status === '1'"
                  text="进行中"
                  type="warning"
                  size="small"
                />
                <uni-tag
                  v-if="item.status === '2'"
                  text="已完成"
                  type="success"
                  size="small"
                />
              </view>
            </view>
          </view>
        </block>
      </radio-group>
    </view>
  </view>
</template>

<script setup>
const sts = ref(0);
const title = ref("");
const current = ref(1);
const size = ref(10);
const pages = ref(0);
const tagid = ref(0);
/**
 * 生命周期函数--监听页面加载
 */
onLoad((options) => {
  current.value = 1;
  pages.value = 0;

  if (options.tagid) {
    tagid.value = options.tagid;
  }

  loadPandianReportData(options);
});

/**
 * 页面上拉触底事件的处理函数
 */
onReachBottom(() => {
  if (current.value < pages.value) {
    current.value = current.value + 1;
    loadPandianReportData();
  }
});

/**
 * 加载盘点报告数据列表
 */
const loadPandianReportData = (options) => {
  const stsParam = sts.value;
  getPandian4Fixed();
};
const pandianReportList = ref([]);
const getPandian4Fixed = () => {
  uni.showLoading();
  http
    .request({
      url: "/app/api/getPandian4Fixed?pageNum=1&pageSize=50",
      method: "GET"
    })
    .then(({ data }) => {
      pandianReportList.value = data;
      uni.hideLoading();
    });
};
/**
 * 获取我的收藏商品
 */
const getCollectionProd = () => {
  uni.showLoading();
  http
    .request({
      url: "/p/user/collection/prods",
      method: "GET",
      data: {
        current: current.value,
        size: size.value,
      },
    })
    .then(({ data }) => {
      let list;
      if (data.current == 1) {
        list = data.records;
      } else {
        list = prodList.value;
        list = list.concat(data.records);
      }
      prodList.value = list;
      pages.value = data.pages;
      uni.hideLoading();
    });
};

/**
 * 获取标签列表
 */
const getTagProd = () => {
  uni.showLoading();
  http
    .request({
      url: "/prod/prodListByTagId",
      method: "GET",
      data: {
        tagId: tagid.value,
        current: current.value,
        size: size.value,
      },
    })
    .then(({ data }) => {
      let list;
      if (data.current === 1) {
        list = data.records;
      } else {
        list = prodList.value.concat(data.records);
      }
      prodList.value = list;
      pages.value = data.pages;
      uni.hideLoading();
    });
};

/**
 * 获取优惠券商品列表
 */
const getProdByCouponId = (id) => {
  uni.showLoading();
  http
    .request({
      url: "/coupon/prodListByCouponId",
      method: "GET",
      data: {
        couponId: id,
        current: current.value,
        size: size.value,
      },
    })
    .then(({ data }) => {
      let list;
      if (data.current === 1) {
        list = data.records;
      } else {
        list = prodList.value.concat(data.records);
      }
      prodList.value = list;
      pages.value = data.pages;
      uni.hideLoading();
    });
};

const toPandianReportDetail = (e) => {
  const pandianReportId = e.currentTarget.dataset.reportId;
  uni.navigateTo({
    url: "/pages/pandian/pandianReportDetail?reportId=" + pandianReportId,
  });
};
</script>

<style scoped lang="scss">
@use "./pandian.scss";
</style>
